package com.kazimsoylu;

import net.sf.jml.MsnContact;
import net.sf.jml.MsnMessenger;
import net.sf.jml.MsnSwitchboard;
import net.sf.jml.event.MsnMessageAdapter;
import net.sf.jml.message.MsnControlMessage;
import net.sf.jml.message.MsnInstantMessage;
import net.sf.jml.message.MsnSystemMessage;

import com.kazimsoylu.gui.ConversationWindow;

public class IncomingMessageHandler extends MsnMessageAdapter
{
	@Override
	public void controlMessageReceived(MsnSwitchboard sw,MsnControlMessage message, MsnContact contact) 
	{	
		System.out.println("Yazıyor:"+message.getTypingUser());
		ConversationWindow cw = Application.getConversation( contact );
		if( cw == null )
		{			
			cw = new ConversationWindow( contact );
			Application.addConversation(contact, cw);
			cw.setVisible(true);
			
		}
		cw.setStatusText( message.getTypingUser()+" yazıyor..." );
	}

	@Override
	public void instantMessageReceived(MsnSwitchboard switchboard,MsnInstantMessage message, MsnContact contact) 
	{
		System.out.println( "Mesaj:"+message.getContent()+"-Kimden:"+contact.getDisplayName() );
		
		ConversationWindow cw = Application.getConversation( contact );
		if( cw == null )
		{			
			cw = new ConversationWindow( contact );
			Application.addConversation(contact, cw);
			cw.setVisible(true);
			
			//Application.addSwitchBoard( contact , switchboard);
		}
		cw.addMessage( message );
	
	}

	@Override
	public void systemMessageReceived(MsnMessenger msn, MsnSystemMessage message) 
	{
		System.out.println( "System:"+ message.getContent() );		
	}

}
